package com.hn.birthdaymatch.utils;

import org.springframework.util.StringUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @ClassName ValidateUtils
 * @Description 前端校验工具类
 * @Author Ts-SuSu
 * @Date  2024/4/28 6:08
 * @Version 1.0
 **/
public class ValidateUtils {

    /**
     * 判断是否是email
     *
     * @param inputStr
     * @return
     */
    public static boolean isEmail(Object inputStr) {

        try {
            final String reg="^([a-zA-Z0-9]*[-_]?[a-zA-Z0-9]+)*@([a-zA-Z0-9]*[-_]?[a-zA-Z0-9]+)+[\\.][A-Za-z]{2,3}([\\.][A-Za-z]{2})?$";
            Pattern p=Pattern.compile(reg);
            Matcher m=p.matcher(inputStr.toString());
            if(!m.matches()){
                return false;
            };
            return true;
        } catch (Exception e) {
            return false;
        }
    }

    /**
     * 判断是否是必填字符
     *
     * @param
     * @return boolean true:不为空 false:为空
     */
    public static boolean isRequired(Object inputStr) {
        try {
            if (null == inputStr || StringUtils.isEmpty(inputStr)
                    || "".equals(inputStr.toString().trim())
                    || "null".equals(inputStr)) {
                return false;
            }
            return true;
        } catch (Exception e) {
            return false;
        }
    }


}
